package com.example.domain;

import com.example.domain.property.Comment;
import com.example.domain.property.Tag;
import com.example.domain.property.Type;
import com.example.domain.property.User;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@Entity  //声明此类是一个实体类
@Table(name = "t_blog")   //配置实体类和表的映射关系,name:配置数据库表的名称
public class Blog {
    @Id   //声明主键的配置
    @GeneratedValue(strategy = GenerationType.IDENTITY)  //主键生成策略,IDENTITY自增
    private Long id;   //文章id

    private String title;  //文章标题
    @Basic(fetch = FetchType.LAZY)  //懒加载
    @Lob  //表示大字段类型
    private String content;  //文章内容
    private String firstPicture;  //首图地址
    private String flag;  //原创，转载，。。。
    private Integer views;  //浏览次数

    private boolean appreciation;  //赞赏是否开启
    private boolean shareStatement;  //版权是否开启
    private boolean commentabled;  //评论是否开启
    private boolean published;  //发布是否
    private boolean recommend;  //推荐是否

    @JsonFormat(shape= JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone="GMT+8")
    private Date createTime;   //文章创建时间
    @JsonFormat(shape= JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone="GMT+8")
    private Date updateTime;   //文章更新时间

    @ManyToOne   //多的一端
    @JsonIgnoreProperties("blogList")   //调用到对方blogList时停止
    @ToString.Exclude  //toString方法中除去此字段
    private Type type;  //分类实体类

    @ManyToMany(cascade = {CascadeType.PERSIST})  //级联新增
    @JsonIgnoreProperties("blogList")
    @ToString.Exclude
    private List<Tag> tagList; //标签实体类

    @ManyToOne   //多的一端
    @JsonIgnoreProperties("blogList")
    @ToString.Exclude
    private User user;  //用户实体类

    @OneToMany(mappedBy = "blog")
    private List<Comment> comments; //评论实体类

    //新增文章时的标签id组
    @Transient   //不加入数据库查询
    private String tagIds;
    //分页组
    @Transient   //不加入数据库查询
    private Long typeId;
    @Basic(fetch = FetchType.LAZY)  //懒加载
    @Lob  //表示大字段类型
    private String description;
}
